//
//  PCDApiTimeOutToLogin.m
//  PCDBankSix
//
//  Created by Jason Tao on 2022/4/26.
//

#import "PCDApiTimeOutToLogin.h"
#import "PCDDataBaseModel.h"

@implementation PCDApiTimeOutToLogin

- (void)handler:(id)data andContext:(PCDContext *)context ResponseCallback:(WVJBResponseCallback )responseCallback
{
      
    UIViewController *bankWebViewController = context.viewController;
    //退出登录
    [PCDUtil saveLoginSession:nil];
    //清空内存缓存信息
    [[PCDDataBaseModel shareModel].memoryStorage removeAllObjects];
    //清理所有栈内页面
    NSMutableArray *viewCtrs =[self clearViews];
    NSDictionary *params = @{@"ShowType":[NSNumber numberWithInt:0],@"FromWeb":@"Y"};
    UIViewController *viewController= [[CTMediator sharedInstance] CTMediatorLoginViewController:params CompleteAction:^(BOOL isSuccess, id session) {
        if (isSuccess) {
            
        }
    }];
    
    [bankWebViewController.navigationController pushViewController:viewController animated:YES];
}

-(NSMutableArray *)clearViews
{
    NSMutableArray *viewCtrs = [NSMutableArray arrayWithArray:PCDPageViewMangeGet().baseNavgatView.viewControllers];
    
    NSInteger i =viewCtrs.count-1;
    while (i>=0) {
        
        id view = [viewCtrs objectAtIndex:i];
        
        if ([view isKindOfClass:[PCDBankWebViewController class]]) {
            [viewCtrs removeObjectAtIndex:i];
            i--;
        }else{
            break;
        }

    }
    
    return viewCtrs;
}

@end
